package Homework5

import java.time.{Instant, LocalDateTime}

import akka.actor.{Actor, ActorRef, ActorSystem, Props}

import scala.collection.mutable

class Master extends Actor{
  var workMap = new mutable.HashMap[String, Instant]()
  val masterCheck: ActorRef = ActorSystem("as").actorOf(Props[MasterCheck], "ms")
  masterCheck ! workMap
  override def receive: Receive = {
    case name: String => {
      workMap.get(name) match {
        case None => {
          workMap(name) = Instant.now()
          sender() ! "注册成功"
          println("注册成功")
        }
        case Some(x) => workMap(name) = Instant.now()
          println("收到" + name + "心跳")
          println(workMap)
      }
    }
  }
}
